{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Probability ratio encoding\n",
    "\n",
    "In the previous lectures in this section on how to engineer the labels of categorical variables, you learnt how to convert a label into a number, by using one hot encoding or replacing by frequency or counts. These methods are simple, make no assumptions and work generally well in different scenarios.\n",
    "\n",
    "There are however methods that allow us to capture information while pre-processing the labels of categorical variables. These methods include:\n",
    "\n",
    "- Ordering the labels according to the target\n",
    "- Replacing labels by the risk (of the target)\n",
    "- Replacing the labels by the joint probability of the target being 1 or 0\n",
    "- Weight of evidence.\n",
    "\n",
    "### Monotonicity\n",
    "\n",
    "All these methods create a monotonic relationship between the categorical variable and the target. A monotonic relationship is a relationship that does one of the following: (1) as the value of one variable increases, so does the value of the other variable; or (2) as the value of one variable increases, the other variable value decreases. In this case, as the value of the independent variable (predictor) increases, so does the target, or conversely, as the value of the variable increases, the target decreases.\n",
    "\n",
    "In general:\n",
    "\n",
    "### Advantages\n",
    "\n",
    "- Capture information within the label, therefore rendering more predictive features\n",
    "- Creates a monotonic relationship between the variable and the target\n",
    "- Does not expand the feature space\n",
    "\n",
    "### Disadvantage\n",
    "\n",
    "- Prone to cause over-fitting\n",
    "\n",
    "\n",
    "### Note\n",
    "\n",
    "The methods discussed in this and the coming 3 lectures can be also used on numerical variables, after discretisation. This creates a monotonic relationship between the numerical variable and the target, and therefore improves the performance of linear models. I will discuss this in more detail in the section \"Discretisation\".\n",
    "\n",
    "\n",
    "### Replace labels by joint probability of the target being 1 or 0\n",
    "\n",
    "For each label, we calculate the mean of target=1, that is the probability of being 1 ( P(1) ), and also the probability of the target=0 ( P(0) ). And then, we calculate the ratio P(1)/P(0), and replace the labels by that ratio."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from sklearn.model_selection import train_test_split\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Survived</th>\n",
       "      <th>Cabin</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>C85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>C123</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Survived Cabin\n",
       "0         0   NaN\n",
       "1         1   C85\n",
       "2         1   NaN\n",
       "3         1  C123\n",
       "4         0   NaN"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# let's load again the titanic dataset\n",
    "\n",
    "data = pd.read_csv('titanic.csv', usecols=['Cabin', 'Survived'])\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Survived</th>\n",
       "      <th>Cabin</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>Missing</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>C85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>Missing</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>C123</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>Missing</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Survived    Cabin\n",
       "0         0  Missing\n",
       "1         1      C85\n",
       "2         1  Missing\n",
       "3         1     C123\n",
       "4         0  Missing"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# let's first fill NA values with an additional label\n",
    "\n",
    "data.Cabin.fillna('Missing', inplace=True)\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "148"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Cabin has indeed a lot of labels, here for simplicity, I will capture the first letter of the cabin, \n",
    "# but the procedure could be done as well without any prior variable manipulation\n",
    "\n",
    "len(data.Cabin.unique())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Survived</th>\n",
       "      <th>Cabin</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>M</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Survived Cabin\n",
       "0         0     M\n",
       "1         1     C\n",
       "2         1     M\n",
       "3         1     C\n",
       "4         0     M"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Now we extract the first letter of the cabin\n",
    "\n",
    "data['Cabin'] = data['Cabin'].astype(str).str[0]\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['M', 'C', 'E', 'G', 'D', 'A', 'B', 'F', 'T'], dtype=object)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# check the labels\n",
    "data.Cabin.unique()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Important\n",
    "\n",
    "The calculation of the probability ratios to replace the labels should be done considering ONLY on the training set, and then expanded it to the test set.\n",
    "See below."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((623, 2), (268, 2))"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Let's separate into training and testing set\n",
    "\n",
    "X_train, X_test, y_train, y_test = train_test_split(data[['Cabin', 'Survived']],\n",
    "                                                    data.Survived, test_size=0.3,\n",
    "                                                    random_state=0)\n",
    "X_train.shape, X_test.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Cabin\n",
       "A    0.428571\n",
       "B    0.774194\n",
       "C    0.571429\n",
       "D    0.692308\n",
       "E    0.740741\n",
       "F    0.666667\n",
       "G    0.500000\n",
       "M    0.303609\n",
       "T    0.000000\n",
       "Name: Survived, dtype: float64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# let's calculate the probability of Survived (target=1)\n",
    "X_train.groupby(['Cabin'])['Survived'].mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Survived</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Cabin</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>0.428571</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>0.774194</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>0.571429</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>0.692308</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>0.740741</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>0.666667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>0.500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>0.303609</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       Survived\n",
       "Cabin          \n",
       "A      0.428571\n",
       "B      0.774194\n",
       "C      0.571429\n",
       "D      0.692308\n",
       "E      0.740741\n",
       "F      0.666667\n",
       "G      0.500000\n",
       "M      0.303609\n",
       "T      0.000000"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# let's make a dataframe with the above\n",
    "\n",
    "prob_df = X_train.groupby(['Cabin'])['Survived'].mean()\n",
    "prob_df = pd.DataFrame(prob_df)\n",
    "prob_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Survived</th>\n",
       "      <th>Died</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Cabin</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>0.428571</td>\n",
       "      <td>0.571429</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>0.774194</td>\n",
       "      <td>0.225806</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>0.571429</td>\n",
       "      <td>0.428571</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>0.692308</td>\n",
       "      <td>0.307692</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>0.740741</td>\n",
       "      <td>0.259259</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>0.666667</td>\n",
       "      <td>0.333333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>0.500000</td>\n",
       "      <td>0.500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>0.303609</td>\n",
       "      <td>0.696391</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       Survived      Died\n",
       "Cabin                    \n",
       "A      0.428571  0.571429\n",
       "B      0.774194  0.225806\n",
       "C      0.571429  0.428571\n",
       "D      0.692308  0.307692\n",
       "E      0.740741  0.259259\n",
       "F      0.666667  0.333333\n",
       "G      0.500000  0.500000\n",
       "M      0.303609  0.696391\n",
       "T      0.000000  1.000000"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# now let's  calculate the probability of target = 0 (people who did not survive)\n",
    "prob_df = X_train.groupby(['Cabin'])['Survived'].mean()\n",
    "prob_df = pd.DataFrame(prob_df)\n",
    "prob_df['Died'] = 1-prob_df.Survived\n",
    "prob_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Survived</th>\n",
       "      <th>Died</th>\n",
       "      <th>ratio</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Cabin</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>0.428571</td>\n",
       "      <td>0.571429</td>\n",
       "      <td>0.750000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>0.774194</td>\n",
       "      <td>0.225806</td>\n",
       "      <td>3.428571</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>0.571429</td>\n",
       "      <td>0.428571</td>\n",
       "      <td>1.333333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>0.692308</td>\n",
       "      <td>0.307692</td>\n",
       "      <td>2.250000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>0.740741</td>\n",
       "      <td>0.259259</td>\n",
       "      <td>2.857143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>0.666667</td>\n",
       "      <td>0.333333</td>\n",
       "      <td>2.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>0.500000</td>\n",
       "      <td>0.500000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>0.303609</td>\n",
       "      <td>0.696391</td>\n",
       "      <td>0.435976</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       Survived      Died     ratio\n",
       "Cabin                              \n",
       "A      0.428571  0.571429  0.750000\n",
       "B      0.774194  0.225806  3.428571\n",
       "C      0.571429  0.428571  1.333333\n",
       "D      0.692308  0.307692  2.250000\n",
       "E      0.740741  0.259259  2.857143\n",
       "F      0.666667  0.333333  2.000000\n",
       "G      0.500000  0.500000  1.000000\n",
       "M      0.303609  0.696391  0.435976\n",
       "T      0.000000  1.000000  0.000000"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#  and now the ratio\n",
    "\n",
    "prob_df['ratio'] = prob_df.Survived/prob_df.Died\n",
    "prob_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'A': 0.75,\n",
       " 'B': 3.4285714285714279,\n",
       " 'C': 1.3333333333333333,\n",
       " 'D': 2.25,\n",
       " 'E': 2.8571428571428563,\n",
       " 'F': 1.9999999999999998,\n",
       " 'G': 1.0,\n",
       " 'M': 0.4359756097560975,\n",
       " 'T': 0.0}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# let's make a dictionary with the above ratio\n",
    "\n",
    "prob_df['ratio'].to_dict()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "ordered_labels = prob_df['ratio'].to_dict()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# replace the labels with the ratios\n",
    "\n",
    "X_train['Cabin_ordered'] = X_train.Cabin.map(ordered_labels)\n",
    "X_test['Cabin_ordered'] = X_test.Cabin.map(ordered_labels)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Cabin</th>\n",
       "      <th>Survived</th>\n",
       "      <th>Cabin_ordered</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>857</th>\n",
       "      <td>E</td>\n",
       "      <td>1</td>\n",
       "      <td>2.857143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>D</td>\n",
       "      <td>1</td>\n",
       "      <td>2.250000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>386</th>\n",
       "      <td>M</td>\n",
       "      <td>0</td>\n",
       "      <td>0.435976</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>124</th>\n",
       "      <td>D</td>\n",
       "      <td>0</td>\n",
       "      <td>2.250000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>578</th>\n",
       "      <td>M</td>\n",
       "      <td>0</td>\n",
       "      <td>0.435976</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    Cabin  Survived  Cabin_ordered\n",
       "857     E         1       2.857143\n",
       "52      D         1       2.250000\n",
       "386     M         0       0.435976\n",
       "124     D         0       2.250000\n",
       "578     M         0       0.435976"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# check the results\n",
    "\n",
    "X_train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.text.Text at 0x8813c6f860>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEWCAYAAACJ0YulAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xd4FWXa+PHvnYSeUJPQIYQWitQIKB10xYqFVRDFCqKi\n69p3f7uu7+v6rqvuWkFEbKCCXXEXO6CAtID0GmpCS2gh1LT798cMeIypcE7mnOT+XFeunJl5Zp57\n5pwz95n2PKKqGGOMMQBhXgdgjDEmeFhSMMYYc5olBWOMMadZUjDGGHOaJQVjjDGnWVIwxhhzmiWF\nECAij4vIO35c3jYRueAM5+0rIhv8FUshdbwlIn8vYvoREYk/g+XGiYiKSMTZRVgxiMhEEflrCcvO\nEZHbC5kWFNs9WOIIdpYUOL2TTBORGj7jbheROR6GFRTc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1A6fTQCeMF9Pd0dDsYdm+8pj/OAKSLSUe3e3/IsqE/J5BNKsSIi43HOEGSp6rlex+NLVVe612RG\nkK8zsVAWEklBROriHFaeIyKK82tRReShYN7ZquoCEYkGYoA0r+PxsQYY5nUQpSUi8UAuwbUtjX+t\nAa45NaCqd7vfoRK12+OBGcCzwACgnreh+EeonD4aBkxV1eaqGqeqTYGtQF+P4yqSe5dUOLDf61jy\nmQVUEZExp0aISCcRCdrtKSIxwETg5WD+IWDO2iygqojc6TOuulfBlMAbwP+o6iqvA/GXkDhSwDk8\n+2e+cR+7438s+3CKVE1ElruvBbhJVXO9DCg/VVX3Fr/nReQR4ASwDbjP08B+69S2rATkAFOBf3sb\nUoF833Nwrn0F7W2pwcz9bF4JPCciDwPpOHf6POJtZAVT1VTgRa/j8Cdr5sIYY8xpoXL6yBhjTBmw\npGCMMeY0SwrGGGNOs6RgjDHmNEsKxhhjTrOkYEwhStOSrIjEicjqQqZNFpH2gY3WGP8IlecUjClT\n/mxJVlVv93+ExgSGHSkYU7ACW5IFfhaR792+MlaJyFCfeSJE5F0RWSciH4lIdQARmSMiie7rIyLy\npNs/xEIRqV+ma2VMMSwpGFOwwlqSPQFcpardcBLHv3ya8m4LTFDVdsBh4K4C5q8BLFTVzjhP44/2\ne+TGnAVLCsaUjgD/JyIrge+AxjinlABSVHW++/odnNY988sCTvXOtRSIC1yoxpSeJQVjCrYGKKjP\njpE4rd52d5ug3gtUdaflbzOmoDZksn0a9MvFruuZIGNJwZiCFdiSLNAcSFPVbBEZ6A6f0sztQwPg\nepyuY40JKZYUjCmA+2v+KuAC95bUNTj9bc8EEkVkFTAKWO8z2wbgbhFZB9QBXinjsI05a9ZKqjHG\nmNPsSMEYY8xplhSMMcacZknBGGPMaZYUjDHGnGZJwRhjzGmWFIwxxpxmScEYY8xp/x+KMNHhJfml\nDQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x8812c10048>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# plot the original variable\n",
    "\n",
    "fig = plt.figure()\n",
    "fig = X_train.groupby(['Cabin'])['Survived'].mean().plot()\n",
    "fig.set_title('Normal relationship between variable and target')\n",
    "fig.set_ylabel('Survived')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.text.Text at 0x88140ebf60>"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEXCAYAAABCjVgAAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xd4HOW59/HvbUnutoQtucpyr4ANtjDNdAjGSV6HcoKp\nBwIhJJQkJwVSDiGFQEg7ToA4DnEIJXEIpjjBxPQeiAu2cUeuktwkF9mWiyzpfv+YkVgLlZWs9e5K\nv8916dLuzDOz98zszj3zzMzzmLsjIiIC0CbeAYiISOJQUhARkWpKCiIiUk1JQUREqikpiIhINSUF\nERGppqSQZMxsmZmdfRQ+53Uzu7GJ0+aY2V4zS2nuuCI+424ze7ye8U1eT2bmZjakycG1Imb2XTN7\nOMqyj5jZT+oZnxDrPVHiiJcWnxTMbL2ZlZlZZo3hH4Qbf0CMP7/enVdjufux7v56c82vOYTr+Pyq\n9+6+0d07u3tFvGKK13pqbTsUd/+puzfp4CEZHcnBUjN9frPuT2rT4pNCaB1wRdUbMzse6Bi/cOLL\nzFLjHYMkP32PGi8p1pm7t+g/YD3wfWBexLBfAN8DHBgQDksHHgWKgA3hNG3CcdcBb4fT7SRIMhdF\nzK8PMBvYAeQBXwyHTwTKgEPAXmBxfeXDcXcDT4ax7AGWAbk1luf88HUK8F1gTVh2AdCvlnUwIFzW\nG4CNwJvh8FOAd4FdwGLg7IhpXgduDF8PBl4FtgPFwBNARjjuMaAS2B8u47cjPi+1GZb3DqAwHL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qo+EhGRakoKIiJSTUlBRESqKSmI\niEi1/w/AzFGelvprTQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x8812c10198>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# plot the transformed result: the monotonic variable\n",
    "\n",
    "fig = plt.figure()\n",
    "fig = X_train.groupby(['Cabin_ordered'])['Survived'].mean().plot()\n",
    "fig.set_title('Monotonic relationship between variable and target')\n",
    "fig.set_ylabel('Survived')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "As you can see in the above plot, there is now a monotonic relationship between the variable Cabin and probability of survival. The higher the Cabin number, the more likely the person was to survive.\n",
    "\n",
    "### Note\n",
    "\n",
    "Monotonic does not mean strictly linear. Monotonic means that it increases constantly, or it decreases constantly."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  },
  "toc": {
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": "block",
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
